package com.ruoyi.web.controller.system;

import java.text.ParseException;
import java.util.List;

import com.ruoyi.system.service.IApplianceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppliDetail;
import com.ruoyi.system.service.IAppliDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租赁采购Controller
 * 
 * @author ruoyi
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/system/detail")
public class AppliDetailController extends BaseController
{
    @Autowired
    private IAppliDetailService appliDetailService;

    @Autowired
    private IApplianceService applianceService;

    /**
     * 查询租赁采购列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppliDetail appliDetail)
    {
        startPage();
        List<AppliDetail> list = appliDetailService.selectAppliDetailList(appliDetail);
        return getDataTable(list);
    }

    /**
     * 导出租赁采购列表
     */
    @Log(title = "租赁采购", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppliDetail appliDetail)
    {
        List<AppliDetail> list = appliDetailService.selectAppliDetailList(appliDetail);
        ExcelUtil<AppliDetail> util = new ExcelUtil<AppliDetail>(AppliDetail.class);
        return util.exportExcel(list, "租赁采购数据");
    }

    /**
     * 获取租赁采购详细信息
     */
    @GetMapping(value = "/{appliId}")
    public AjaxResult getInfo(@PathVariable("appliId") Long appliId) throws ParseException {
        return AjaxResult.success(appliDetailService.queryAppliDetailListById(appliId));
    }

    /**
     * 新增租赁采购
     */
    @Log(title = "租赁采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppliDetail appliDetail) throws ParseException {
        return toAjax(appliDetailService.insertAppliDetail(appliDetail));
    }

    /**
     * 修改租赁采购
     */
    @Log(title = "租赁采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppliDetail appliDetail) throws ParseException {
        return toAjax(appliDetailService.updateAppliDetail(appliDetail));
    }


    /**
     * 删除租赁采购
     */
    @Log(title = "租赁采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appliId}")
    public AjaxResult remove(@PathVariable Long appliId)
    {
        return toAjax(applianceService.deleteAppliDetailById(appliId));
    }
}
